const getFileName=(res) =>{
  //切割出文件名
  let fileNameEncode = (res.headers['content-disposition'] || '').split('filename=')[1]
  //解码
  return decodeURIComponent(fileNameEncode)
}

const downLoad=(blob,fileName)=>{
  let link = document.createElement('a')
  link.style.display = "none";
  link.href = URL.createObjectURL(blob);
  link.setAttribute('download', `${fileName}`)
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}



export const ExcelDownLoad = (res) => {
  let fileName=getFileName(res)
  const blob = new Blob([res.data], {
    type: 'application/vnd.ms-excel; charset=utf-8'
  })
  downLoad(blob,fileName)
}

export const WordDownLoad = (res) => {
  let fileName=getFileName(res)
  const blob = new Blob([res.data], {
    type: 'application/msword; charset=utf-8'
  })
  downLoad(blob,fileName)
}